package com.zhy.http.okhttp.request;

import android.os.Handler;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder.FileInput;
import com.zhy.http.okhttp.callback.Callback;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import okhttp3.FormBody.Builder;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody.Builder;
import okhttp3.Request;
import okhttp3.Request.Builder;
import okhttp3.RequestBody;

public class PostFormRequest extends OkHttpRequest
{
  private List<PostFormBuilder.FileInput> files;

  public PostFormRequest(String paramString, Object paramObject, Map<String, String> paramMap1, Map<String, String> paramMap2, List<PostFormBuilder.FileInput> paramList)
  {
    super(paramString, paramObject, paramMap1, paramMap2);
    this.files = paramList;
  }

  private void addParams(FormBody.Builder paramBuilder)
  {
    if ((this.params == null) || (this.params.isEmpty()))
      paramBuilder.add("1", "1");
    while (true)
    {
      return;
      Iterator localIterator = this.params.keySet().iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        paramBuilder.add(str, (String)this.params.get(str));
      }
    }
  }

  private void addParams(MultipartBody.Builder paramBuilder)
  {
    Iterator localIterator;
    if ((this.params != null) && (!this.params.isEmpty()))
      localIterator = this.params.keySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      String str = (String)localIterator.next();
      String[] arrayOfString = new String[2];
      arrayOfString[0] = "Content-Disposition";
      arrayOfString[1] = ("form-data; name=\"" + str + "\"");
      paramBuilder.addPart(Headers.of(arrayOfString), RequestBody.create(null, (String)this.params.get(str)));
    }
  }

  private String guessMimeType(String paramString)
  {
    String str = URLConnection.getFileNameMap().getContentTypeFor(paramString);
    if (str == null)
      str = "application/octet-stream";
    return str;
  }

  protected Request buildRequest(Request.Builder paramBuilder, RequestBody paramRequestBody)
  {
    return paramBuilder.post(paramRequestBody).build();
  }

  protected RequestBody buildRequestBody()
  {
    if ((this.files == null) || (this.files.isEmpty()))
    {
      FormBody.Builder localBuilder = new FormBody.Builder();
      addParams(localBuilder);
      return localBuilder.build();
    }
    MultipartBody.Builder localBuilder1 = new MultipartBody.Builder().setType(MultipartBody.FORM);
    addParams(localBuilder1);
    for (int i = 0; ; i++)
    {
      if (i >= this.files.size())
        return localBuilder1.build();
      PostFormBuilder.FileInput localFileInput = (PostFormBuilder.FileInput)this.files.get(i);
      RequestBody localRequestBody = RequestBody.create(MediaType.parse(guessMimeType(localFileInput.filename)), localFileInput.file);
      localBuilder1.addFormDataPart(localFileInput.key, localFileInput.filename, localRequestBody);
    }
  }

  public String toString()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append(super.toString());
    Iterator localIterator;
    if (this.files != null)
      localIterator = this.files.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return localStringBuilder.toString();
      localStringBuilder.append(((PostFormBuilder.FileInput)localIterator.next()).toString() + "  ");
    }
  }

  protected RequestBody wrapRequestBody(RequestBody paramRequestBody, final Callback paramCallback)
  {
    if (paramCallback == null)
      return paramRequestBody;
    return new CountingRequestBody(paramRequestBody, new CountingRequestBody.Listener()
    {
      public void onRequestProgress(final long paramAnonymousLong1, long paramAnonymousLong2)
      {
        OkHttpUtils.getInstance().getDelivery().post(new Runnable()
        {
          public void run()
          {
            this.val$callback.inProgress(1.0F * (float)paramAnonymousLong1 / (float)this.val$contentLength);
          }
        });
      }
    });
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.zhy.http.okhttp.request.PostFormRequest
 * JD-Core Version:    0.6.2
 */